#include <bits/stdc++.h>

#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define in read<int>()
#define lin read<ll>()
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using vec = vector < int >;
using veg = vector < pii >;

template < typename T > T read() {
	T x = 0; bool f = 0; char ch = getchar();
	while(!isdigit(ch)) f |= ch == '-', ch = getchar();
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

template < typename T > void chkmax(T &x, const T &y) { x = x > y ? x : y; }
template < typename T > void chkmin(T &x, const T &y) { x = x < y ? x : y; }

const int mod = 1e9 + 7;

ll qp(ll x, int t) { ll res = 1; for(; t; t >>= 1, x = x * x % mod) if(t & 1) res = res * x % mod; return res; }
int phi(int x) {
	int up = sqrt(x), res = x;
	rep(i, 2, up) {
		if(i * i > x) break; if(x % i) continue;
		res = res / i * (i - 1);
		while(x % i == 0) x /= i; 
	} if(x > 1) res = res / x * (x - 1);
	return res;
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("1.in", "r", stdin);
#endif
	int T = in;
	while(T--) {
		int n = in, up = sqrt(n), ans = 0;
		rep(i, 1, up) {
			if(n % i) continue;
			ans = (ans + qp(n, i) * phi(n / i) % mod) % mod;
			if(i * i != n) ans = (ans + qp(n, n / i) * phi(i) % mod) % mod;
		} printf("%lld\n", qp(n, mod - 2) * ans % mod);
	}
	return 0;
}
